
#include "Weapon.h"

CWeapon::CWeapon()
{

}

CWeapon::~CWeapon()
{

}

CWeapon* CWeapon::creatWithDt(CWeaponData* dt)
{
	CWeapon* weapon = new CWeapon();
	if (weapon && weapon->initWithDt(dt)){
		weapon->autorelease();
		return weapon;
	}
	delete weapon;
	weapon = nullptr;
	return nullptr;
}

bool CWeapon::initWithDt(CWeaponData* dt)
{
	if (!Node::init()){
		return false;
	}
	m_pWeapon = Sprite::createWithSpriteFrameName(dt->strPicName);
	this->addChild(m_pWeapon);
	m_pWeapon->setAnchorPoint(Vec2(0.35, 0.5));

	emptyNode = Node::create();
	m_pWeapon->addChild(emptyNode);
	emptyNode->setPosition(Vec2(m_pWeapon->getContentSize().width / 1.25, -2));

	m_nBulletId = dt->nBulletId;

	return true;
}

Sprite* CWeapon::getWeaponPic()
{
	return m_pWeapon;
}

cocos2d::Vec2 CWeapon::getShootPoint()
{
	return m_pWeapon->convertToWorldSpaceAR(emptyNode->getPosition());
}

